package ordemServico;

import java.io.Serializable;
import java.sql.Time;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import usuario.EntidadeCliente;

@Entity
@Table(name = "ordem")
@SequenceGenerator( name = "ORD_ID", sequenceName = "ORD_SEQ", allocationSize = 1 )
public class EntidadeOrdem implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	@Id
	@Column(name = "id")  
    @GeneratedValue( strategy = GenerationType.IDENTITY, generator = "ORD_ID" ) 
	private int id;
	@Column(name = "data") 
	private Date data;
	@Column(name = "horario") 
	private Time horario;
	@ManyToOne
	@JoinColumn(name = "cliord") 
	private EntidadeCliente cliord;
	@OneToMany(mappedBy = "matord", cascade = CascadeType.ALL)
	private List<Item_ord_mat> mat = new ArrayList<Item_ord_mat>();
	@OneToMany(mappedBy = "servord", cascade = CascadeType.ALL)
	private List<Item_ord_serv> serv = new ArrayList<Item_ord_serv>();
	
	public void AdicionarMat_ord(Item_ord_mat material)
	{
		mat.add(material);
		material.setMatord(this);
	}
	public void AdicionarServ_ord(Item_ord_serv servico)
	{
		serv.add(servico);
		servico.setServord(this);
	}
	
	public Date getData() {
		return data;
	}
	public void setData(Date data) {
		this.data = data;
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public Time getHorario() {
		return horario;
	}
	public void setHorario(Time horario) {
		this.horario = horario;
	}
	public EntidadeCliente getCliord() {
		return cliord;
	}
	public void setCliord(EntidadeCliente cliord) {
		this.cliord = cliord;
	}
	public List<Item_ord_mat> getMat() {
		return mat;
	}
	public void setMat(List<Item_ord_mat> mat) {
		this.mat = mat;
	}
	public List<Item_ord_serv> getServ() {
		return serv;
	}
	public void setServ(List<Item_ord_serv> serv) {
		this.serv = serv;
	}
}
